﻿using IOA.MES.Client.Common;
using NLog;
using SuperSocket.SocketBase.Protocol;
using System;
using System.Text;

namespace IOA.MES.Client.Top.TopTcp
{
    public class TopReceiveFilter : IReceiveFilter<StringRequestInfo>
    {
        public IReceiveFilter<StringRequestInfo> NextReceiveFilter => new TopReceiveFilter();

        int IReceiveFilter<StringRequestInfo>.LeftBufferSize { get { return 0; } }

        FilterState IReceiveFilter<StringRequestInfo>.State { get { return FilterState.Normal; } }

        public StringRequestInfo Filter(byte[] readBuffer, int offset, int length, bool toBeCopied, out int rest)
        {
            rest = 0;
            try
            {
                return new StringRequestInfo("", Encoding.ASCII.GetString(readBuffer, offset, length).Replace("\0", ""), new string[] { });
            }
            catch (Exception ex)
            {
                CommonMessage.Log(LogLevel.Fatal, $"Filter异常：{ex.Message}", ex);
            }
            return new StringRequestInfo("", "", new string[] { });
        }

        public void Reset()
        {

        }
    }
}
